package cn.z2huo.knowledge.concurrency.synchronizedkeyword.reentrant;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 *
 * @author z2huo
 */
class SyncBlockTest {

    private final Object lock = new Object();

    public void test() {
        try {
            synchronized (lock) {
                System.out.println("first lock");
                TimeUnit.SECONDS.sleep(10);
                synchronized (lock) {
                    System.out.println("second lock");
                    TimeUnit.SECONDS.sleep(10);
                }
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws InterruptedException {

        SyncBlockTest syncBlockTest = new SyncBlockTest();

        Runnable runnable = syncBlockTest::test;

        Thread thread = new Thread(runnable);
        Thread thread2 = new Thread(runnable);

        thread.start();
        TimeUnit.SECONDS.sleep(1);
        thread2.start();

    }

}
